/*
https://leetcode.cn/problems/rearrange-k-substrings-to-form-target-string/submissions/584124255/
3365. 重排子字符串以形成目标字符串
*/
class Solution {
public:
    bool isPossibleToRearrange(string s, string t, int k) {
        unordered_map<string,int>mp;
        int n=s.size();
        int num=n/k;
        for(int i=0;i<n;i+=num){
           string substring=s.substr(i,num);
            mp[substring]++;
        }
       /* for(auto i:mp){
            cout<<i.first<<" ";
        }*/
        for(int i=0;i<n;i+=num){
           string substring=t.substr(i,num);
            mp[substring]--;
            if(mp[substring]<0) return false;
        }
        return true;
    }
};